﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
    <head>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
        <meta content="history" name="save">
        <title>SA1305: FieldNamesMustNotUseHungarianNotation</title>
        <link rel="stylesheet" type="text/css" href="stylesheets/helpstudio.css"><link rel="stylesheet" type="text/css" href="styles/Presentation.css">
        <script src="script/helpstudio.js" type="text/javascript"></script>
        <script src="script/StandardText.js" type="text/jscript"></script>
    </head>
    <body id="hsbody">
        <input type="hidden" id="userDataCache" class="userDataStyle" name="userDataCache" />
        <div id="allHistory" class="saveHistory" onsave="saveScrollPosition()" onload="loadScrollPosition()"></div>
        <script type="text/jscript">WritePageTop(document.title);</script>
        <div id="pagebody">
            <div id="mainbody">
                <table>
                    <col />
                    <tr><td><p>TypeName</p></td><td><p>FieldNamesMustNotUseHungarianNotation</p></td></tr>
                    <tr><td><p>CheckId</p></td><td><p>SA1305</p></td></tr>
                    <tr><td><p>Category</p></td><td><p>Naming Rules</p></td></tr>
                </table>           
                <h2>Cause</h2>
                <P>The name of a field or variable in C# uses Hungarian notation.</P>
                <H2>Rule Description</H2>
                <P>A violation of this rule occurs when Hungarian notation is used in the naming of fields and variables. The use of Hungarian notation has become widespread in C++ code, but the trend in C# is to use longer, more descriptive names for variables, which are not based on the type of the variable but which instead describe what the variable is used for.</P>
                <P>In addition, modern code editors such as Visual Studio make it easy to identify type information for a variable or field, typically by hovering the mouse cursor over the variable name. This reduces the need for Hungarian notation.</P>
                <P>StyleCop assumes that any variable name that begins with one or two lower-case letters followed by an upper-case letter is making use of Hungarian notation, and will flag a violation of this rule in each case. It is possible to declare certain prefixes as legal, in which case they will be ignored. For example, a variable named <EM>onExecute</EM> will appear to StyleCop to be using Hungarian notation, when in reality it is not. Thus, the <EM>on</EM> prefix should be flagged as an allowed prefix.</P>
                <P>To configure the list of allowed prefixes, bring up the StyleCop settings for a project, and navigate to the Hungarian tab, as shown below:</P>
                <P><IMG alt="" src="Images/HungarianSettings.JPG" border="0"></P>
                <P>Adding a one or two letter prefix to this list will cause StyleCop to ignore variables or fields which begin with this prefix.</P>
                <P>If the field or variable name is intended to match the name of an item associated with Win32 or COM, and thus needs to use Hungarian notation, place the field or variable within a special <EM>NativeMethods</EM> class. A NativeMethods class is any class which contains a name ending in NativeMethods, and is intended as a placeholder for Win32 or COM wrappers. StyleCop will ignore this violation if the item is placed within a NativeMethods class.</P>
                <H2>How to Fix Violations</H2>
                <P>To fix a violation of this rule, remove the Hungarian notation from the field or variable name, or place the item within a NativeMethods class if appropriate.</P>
                <h2>How to Suppress Violations</h2>
                <pre>[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Reviewed.")]</pre>
            </div>
            <script type="text/jscript">WritePageFooter();</script>     
        </div>
    </body>
</html>